package fr.norsys.mapper.console.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import fr.norsys.mapper.console.exception.SessionExpiredException;
import fr.norsys.mapper.console.model.ConsoleCst;

public abstract class BaseAppDispatchAction extends DispatchAction {
	private final static Log log = LogFactory
			.getLog(BaseAppDispatchAction.class);

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward actionForward = null;
		HttpSession session = request.getSession(false);
		if (session == null
				|| session.getAttribute(ConsoleCst.NODE_LIST) == null) {
			throw new SessionExpiredException("session has expired");
		}
		String actionMethod = request.getParameter(mapping.getParameter());
		actionForward = dispatchMethod(mapping, form, request, response,
				actionMethod);
		return actionForward;
	}
}
